﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================

using System;
using System.Windows.Forms;
using DevExpress.Data.Filtering;
using DevExpress.Export;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraTreeList;
using XCI.Helper;
using XCI.Windows;

namespace XCI.Setting.Controls
{
    public partial class SettingTreeOptionsBehavior : BaseUserControl
    {
        private readonly TreeList treeList;
        public SettingTreeOptionsBehavior(TreeList treeList)
        {
            InitializeComponent();
            this.treeList = treeList;
            InitForm();
        }

        private void InitForm()
        {
            if (WinFormHelper.IsDesignMode()) return;

            WinFormHelper.AddEnum(typeof(DefaultBoolean), editAllowExpandAnimation, editAllowCopy, editCopyColumnHeaders);
            WinFormHelper.AddEnum(typeof(TreeListEditingMode), editEditingMode);
            WinFormHelper.AddEnum(typeof(TreeListEditorShowMode),  editEditorShowMode);
            WinFormHelper.AddEnum(typeof(PasteMode), editPasteMode);
            WinFormHelper.AddEnum(typeof(ClipboardMode), editClipboardMode);
            WinFormHelper.AddEnum(typeof(DropNodesMode), editDropNodesMode);
            WinFormHelper.AddEnum(typeof(DragNodesMode), editDragNodesMode);

            WinFormHelper.BindCustomPropertyControlValue(layoutControl1, treeList);
            btnCleanSort.Enabled = treeList.SortedColumnCount > 0;
            btnCleanFilter.Enabled = treeList.ActiveFilter.Count > 0;
        }

        private void btnCleanSort_Click(object sender, EventArgs e)
        {
            if (MessageBoxHelper.ShowWarnYesNo("确定要清除列排序吗？") == DialogResult.Yes)
            {
                treeList.ClearSorting();
                btnCleanSort.Enabled = false;
            }
        }
        
        private void btnCleanFilter_Click(object sender, EventArgs e)
        {
            if (MessageBoxHelper.ShowWarnYesNo("确定要清除列过滤吗？") == DialogResult.Yes)
            {
                treeList.ClearColumnsFilter();
                btnCleanFilter.Enabled = false;
            }

            ////切换到指定的面板
            //layoutControl1.FocusHelper.PlaceItemIntoView(layoutControlGroup3);
        }
    }
}
